package validation

import (
	"gitverse.ru/synapse/kubelatte/pkg/api/v1alpha1"
)

const Validation = "validation"

type Rules struct {
	MutationRuleConfig   []v1alpha1.Item
	ValidationRuleConfig []v1alpha1.Item
}

type RuleSpec struct {
	Type  string          `yaml:"type"`
	Items []v1alpha1.Item `yaml:"items,flow"`
}

type Rule struct {
	Simples []Simple `yaml:"simples"`
	Rego    Rego     `yaml:"rego"`
}

type Rego struct {
	Template   string `yaml:"template"`
	Parameters string `yaml:"parameters"`
}

type Simple struct {
	Name    string `yaml:"name"`
	Path    string `yaml:"path"`
	Value   string `yaml:"value"`
	Action  string `yaml:"action"`
	Message string `yaml:"message"`
}

type Match struct {
	Kinds               []Kinds           `yaml:"kinds"`
	NamespaceSelector   NamespaceSelector `yaml:"namespaceSelector"`
	LabelSelector       LabelSelector     `yaml:"labelSelector"`
	UserInfo            UserInfo          `yaml:"userInfo"`
	Name                string            `yaml:"name"`
	Scope               string            `yaml:"scope"`
	ExcludedNamespaces  []string          `yaml:"excludedNamespaces"`
	Namespaces          []string          `yaml:"namespaces"`
	Operations          []string          `yaml:"operations"`
	AnnotationNamespace string            `yaml:"annotationNamespace"`
	AnnotationTrigger   string            `yaml:"annotationTrigger"`
}

type UserInfo struct {
	Username string `yaml:"username"`
}

type Kinds struct {
	Kinds     []string `yaml:"kinds"`
	ApiGroups []string `yaml:"apiGroups"`
}

type NamespaceSelector struct {
	MatchExpressions []MatchExpression `yaml:"matchExpressions"`
}

type LabelSelector struct {
	MatchExpressions []MatchExpression `yaml:"matchExpressions"`
}

type MatchExpression struct {
	Key      string   `yaml:"key"`
	Operator string   `yaml:"operator"`
	Values   []string `yaml:"values"`
}

const (
	Deny  = "deny"
	Allow = "allow"
)
